﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BanXeTang
{
    public class HighScore
    {
        private int maxHighScore;

        public int MaxHighScore
        {
            get { return maxHighScore; }
            set { maxHighScore = value; }
        }
        private int nHighScore;

        public int NHighScore
        {
            get { return nHighScore; }
            set { nHighScore = value; }
        }
        private List<int> lstHighScore;

        public List<int> LstHighScore
        {
            get { return lstHighScore; }
            set { lstHighScore = value; }
        }

        public void DocFileHighScore(string strPath)
        {
            StreamReader doc = new StreamReader(strPath);
            char[] spliter = { };
            string Line = doc.ReadLine();
            string[] G = Line.Split();
            nHighScore = int.Parse(G[0]);
            for (int i = 0; i < nHighScore; i++)
            {
                Line = doc.ReadLine();
                G = Line.Split(spliter);
                lstHighScore.Add(int.Parse(G[0]));
            }
            doc.Close();
        }
        public void ghiFile(string strPath)
        {
            StreamWriter ghi = new StreamWriter(strPath);
            ghi.WriteLine(lstHighScore.Count.ToString());
            for (int i = 0; i < lstHighScore.Count; i++)
            {
                ghi.WriteLine(lstHighScore[i].ToString());
            }
            ghi.Close();

        }
        public HighScore()
        {
            maxHighScore = 10;
            nHighScore = new int();
            lstHighScore = new List<int>();
        }
        public void insert(int pt)
        {
            for (int i = 0; i < lstHighScore.Count; i++)
            {
                if (pt > lstHighScore[i])
                {
                    lstHighScore.Insert(i, pt);
                    if (lstHighScore.Count > maxHighScore)
                    {
                        lstHighScore.RemoveAt(lstHighScore.Count - 1);
                    }
                    break;
                }
            }
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            int temp = nHighScore;
            if (nHighScore >= 10)
                temp = maxHighScore;
            for (int i = 0; i < temp; i++)
            {
                spriteBatch.DrawString(GlobalSettings.fontChu, lstHighScore[i].ToString(), new Vector2(850, 120 + 50 * (1 + i)), Color.Red);
            }
        }
        public void Update(GameTime gameTime)
        {
            Input.lastKeyboardState = Input.keyboardState;
            Input.keyboardState = Keyboard.GetState();
            if (Input.lastKeyboardState.IsKeyDown(Keys.Escape) && Input.keyboardState.IsKeyUp(Keys.Escape))
            {
                Game1.trangThai = 0;
                Game1.viTriChon = -1;
                Game1.viTriHighLight = 0;
            }
        }
    }
}
